<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 5/25/24
 * Time: 2:06 PM
 */

namespace App\Http\Controllers\Admin;


use App\Services\DepartmentService;
use Illuminate\Http\Request;
use App\Http\Controllers\ResourceController;

class DepartmentController extends ResourceController
{
    protected $service;

    public function __construct(DepartmentService $service)
    {
        $this->service = $service;
    }


    /**
     * 获取部门列表
     *
     * @param Request $request
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getList(Request $request)
    {
        return $this->responseWithSuccess($this->service->getDepList($request->post()));
    }


    /**
     * 创建部门
     *
     * @param Request $request
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function createDepartment(Request $request)
    {
        return $this->service->createDepartment($request->post()) ?
            $this->responseWithSuccess() : $this->responseWithError();
    }


    /**
     * 删除部门
     *
     * @param Request $request
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function delDepartment(Request $request)
    {
        return $this->service->delDepartment($request->post()) ?
            $this->responseWithSuccess() : $this->responseWithError();
    }
}
